package com.zelin.cart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zelin.mapper.StudentMapper;
import com.zelin.pojo.PageUtils;
import com.zelin.pojo.Student;
import com.zelin.pojo.vo.StudentVo;
import com.zelin.cart.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * ------------------------------
 * 功能：
 * 作者：WF
 * 微信：hbxfwf13590332912
 * 创建时间：2021/7/23-15:23
 * ------------------------------
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public PageUtils search(Integer page, Integer pageSize, StudentVo studentVo) {
        IPage<Student> studentPage = new Page<>(page,pageSize);
        //封装查询条件
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        if(studentVo != null){
            if(!StringUtils.isEmpty(studentVo.getSname())){
                wrapper.like("sname","%" + studentVo.getSname() + "%");
            }
            if(!StringUtils.isEmpty(studentVo.getAddr())){
                wrapper.like("addr","%" + studentVo.getAddr() + "%");
            }
            if(studentVo.getCid() != 0){
                wrapper.eq("cid",studentVo.getCid());
            }
        }

        //开始查询
        IPage<Student> studentIPage = studentMapper.selectPage(studentPage, wrapper);
        return new PageUtils(studentIPage);
    }

    /**
     * 功能: 逻辑删除
     * 参数:
     * 返回值: void
     * 时间: 2021/7/23 15:58
     * @param sid
     */
    @Override
    public void delete(Long sid) {
        studentMapper.deleteById(sid);
    }
}
